<?php

//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
$page = new page();
session_start();
$userid = $_SESSION['userid'];

// checking the session
if (!$_SESSION['username']) {
    header("location:../user/login.php");
}
if ($_GET['q'] == 'logout') {
    $page->user_logout();
    header("location:../user/login.php");
}
//If data posted by the form
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $change = $page->change_password($_POST['c_password'], $_POST['n_password']);
    if ($change) {
// Login Success
        $msg = $message[11];
    } else {
        //Login Failed
        $msg = $message[0];
    }
}
include '../../include/navbar.php';
?>
<script>
    if (document.getElementById('password1').value != document.getElementById('password2').value) {
        document.getElementById('password1').setCustomValidity('Passwords must match.');
    } else {
        document.getElementById('password1').setCustomValidity('');
    }
</script>
<!----------------------------------Display the result message of Addition--------------------->
<div align="center"><? echo $msg; ?></div>

<!---------------------------------Login form----------------------------------------->
<div class="login_div" style="width:400px">
    <form class="form-horizontal" method="POST" action="">
        <h2 style="color:#777" class="c_pass">Change Password</h2><br>
        <div class="control-group">
            <label class="control-label" for="inputEmail">Current Password</label>
            <div class="controls">
                <input type="password" id="inputpassword" placeholder="Current Password" name="c_password" required>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputPassword">New Password</label>
            <div class="controls">
                <input type="password" required  id="pwd1" name="n_password" onchange="form.pwd2.pattern = this.value;">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputPassword">Confirm Password</label>
            <div class="controls">
                <input type="password" required  id="pwd2">
            </div>
        </div>
        <div class="control-group">
            <div class="controls">


                <button type="submit" class="btn btn-inverse" style="float:right;">Submit</button>
            </div>
        </div>
    </form>
</div>

<?php

//including footer.php
include '../../include/footer.php';
?>